package com.imooc.ad.entity;

import com.imooc.ad.constant.CommonStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * @Description: TODO
 * @ClassName: AdUser
 * @Author: zhangzhongyu
 * @Date: 2019-10-12 14:53
 * @Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity     // JPA嘛，需要标记为实体类
@Table(name = "ad_user")
public class AdUser {

    @Id
    // 自增的策略
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    // 对应的表列名，不允许为空
    @Column(name = "id", nullable = false)
    private Long id;

    // 数据库表的一个基本属性，对应的相反的标注是@Transient
    @Basic
    @Column(name = "user_name", nullable = false)
    private String username;

    @Basic
    @Column(name = "token", nullable = false)
    private String token;

    @Basic
    @Column(name = "user_status", nullable = false)
    private Integer userStatus;

    @Basic
    @Column(name = "create_time", nullable = false)
    private Date createTime;

    @Basic
    @Column(name = "update_time", nullable = false)
    private Date updateTime;

    public AdUser(String username, String token) {
        this.username = username;
        this.token = token;
        this.userStatus = CommonStatus.VALID.getCode();
        this.createTime = new Date();
        this.updateTime = this.createTime;
    }
}
